package com.icoding.fw.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.icoding.fw.dao.inf.CommonDao;
import com.icoding.fw.service.inf.CommonService;

public abstract class CommonServiceImpl<T> implements CommonService<T> {
	@Autowired
	private CommonDao<T> commonDao;

	private CommonDao<T> getDao() {
		return commonDao;
	}

	@Transactional
	public List<T> getAll() {
		return getDao().loadAll();
	}

	@Transactional
	public T getById(int id) {
		return getDao().get(id);
	}

	@Transactional
	public boolean add(T obj) {
		return getDao().save(obj);
	}

	@Transactional
	public boolean delete(int id) {
		return getDao().delete(id);
	}

	@Transactional
	public boolean update(T obj) {
		return getDao().update(obj);
	}

	@Transactional
	public boolean checkDuplicate(Class<T> clazz, boolean isEqual,
			String columnName, Object value) {
		return getDao().checkDuplicate(clazz, isEqual, columnName, value);
	}

	@Transactional
	public List<T> getListByColumn(Class<T> clazz, boolean isEqual,
			String columnName, Object value) {
		return getDao().getListByColumn(clazz, isEqual, columnName, value);
	}

	@Transactional
	public List<T> getListByMoreColumns(Class<T> clazz, Map<String, Object> map) {
		return getDao().getListByMoreColumns(clazz, map);
	}

	@Transactional
	public boolean checkDuplicateMoreColumns(Class<T> clazz,
			Map<String, Object> map) {
		return getDao().checkDuplicateMoreColumns(clazz, map);
	}

	@Transactional
	public int saveAndGetId(T obj) {
		return getDao().saveAndGetId(obj);
	}
}
